<?php

class Paid_up_members_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "mis_paid_up_members";
        $this->load->model("functions_model");
    }

    function getOne($tid) {
        $data['tid'] = $tid;
        $this->db->where($data);
        $this->db->from($this->tableName);
        $this->db->order_by("tid", "desc");
        $result = array();
        $query = $this->db->get();
        foreach ($query->result_array() as $row) {
            unset($row['tid']);
            $result[] = $row;
        }
        return $result;
    }

    function adminGetAll($field=NULL, $search=NULL, $offset=0, $limit=NULL) {
        if ($field and $search) {
            if ($field == 'all') {
                $this->db->like("names", $search);
                $this->db->or_like("member_no", $search);
                $this->db->or_like("grade", $search);
                $this->db->or_like("phone", $search);
                $this->db->or_like("email", $search);
                $this->db->or_like("branch", $search);
                $this->db->or_like("perm_address", $search);
                $this->db->or_like("town", $search);
                $this->db->or_like("company", $search);
                $this->db->or_like("physical_address", $search);
            } else {
                $data[$field] = $search;
                $this->db->like($data);
            }
        }
        $this->db->order_by("names", "asc");
        $result = array();
        $query = $this->db->get($this->tableName, $limit,$offset);
        $count=$offset;
        foreach ($query->result_array() as $row) {
            $count++;
            //unset($row['tid']);
            unset($row['physical_address']);
            unset($row['phone']);
            unset($row['email']);
            unset($row['perm_address']);
            $row["more"]="<a href='javascript:loadUrl(\"#paidUps_result\",\"" . base_url() . "index.php?/more_info/paidUpMembersMoreInfo/" . $row['tid'] . "\")'>More details</a>";

            $row['tid']=$count;
            $result[] = $row;
        }
        return $result;
    }

}

?>
